package org.kingkong.framework.resolver.bean;

import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.kingkong.framework.annotation.SessionBean;
import org.kingkong.framework.context.ApplicationContextProvider;
import org.springframework.context.ApplicationContext;

@SessionBean
public class BeanResolver extends HashMap<String, Object> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -67082212870301563L;
	private static final Log logger = LogFactory.getLog(BeanResolver.class
			.getSimpleName());
	@Override
	public Object get(Object beanName) {
		Object bean = super.get(beanName);
		if (bean == null) {
			ApplicationContext context = ApplicationContextProvider
					.getApplicationContext();
			bean = context.getBean(beanName.toString());
			super.put(beanName.toString(), bean);
			logger.info(beanName + " resolved");
		}
		return bean;
	}

}
